package edu.chinasoft.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import javax.servlet.annotation.WebServlet;
import org.apache.log4j.Logger;

import edu.chinasoft.pojo.User;
import edu.chinasoft.service.UserService;
import edu.chinasoft.service.UserServiceImp;

/**
 * 
 * @author cjogng
 * @date 2020年1月17日:下午2:26:37
 * @version V1.0
 * @Description: 删除用户
*/
@WebServlet(name="myDeleteUserForServlet",value="/servlet/deleteuserforservlet")
public class  DeleteUserForServlet  extends HttpServlet {
	private static Logger logger = Logger.getLogger( DeleteUserForServlet .class);
	private UserService userService=new UserServiceImp();
	/**
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		logger.debug(" DeleteUserForServlet >doGet start.......");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		
		//获取所要删除用户的id
		String idString = request.getParameter("id");
		//封装到用户里，然后调用服务器层删除用户
		User user = new User();
		user.setId(Integer.parseInt(idString));
		boolean result = userService.deleteUserInfo(user);
		//删除成功，跳到查询用户页面
		
		//删除失败，跳到删除失败页面
		if(result) {
			response.sendRedirect(""+request.getContextPath()+"/servlet/finduserpageforservlet");
		}else {
			response.sendRedirect(""+request.getContextPath()+"/deleteusererror.html");
		}
		
		
		
		logger.debug(" DeleteUserForServlet >doGet end.......");
	}
	
	/**
	 * 
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		logger.debug(" DeleteUserForServlet >doPost start.......");
		this.doGet(request, response);
		
		logger.debug(" DeleteUserForServlet >doPost end.......");
	}
	
}